/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge.major;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import ru.jSkyRoom.interfaces.major.Armature;
import ru.jSkyRoom.interfaces.major.Armor;
import ru.jSkyRoom.interfaces.major.Enchantment;
import ru.jSkyRoom.interfaces.major.Keyword;
import ru.jSkyRoom.interfaces.stub.ImpactSet;
import ru.jSkyRoom.interfaces.stub.EquipSlot;
import ru.jSkyRoom.interfaces.sub.JSkyBodyTemplate;
import ru.jSkyRoom.interfaces.sub.JSkyModel;
import ru.jSkyRoom.interfaces.stub.JSkyScriptPackage;
import ru.jSkyRoom.interfaces.stub.JSkySound;
import ru.jSkyRoom.interfaces.major.Race;


import skyproc.ARMO;
import skyproc.BodyTemplate;
import skyproc.FormID;
import skyproc.ScriptPackage;
import skyproc.genenums.Gender;

/**
 *
 * @author Rakev
 */
public class ArmorBridge extends DescriptionedMajorBridge<ARMO> implements Armor {

    public ArmorBridge(ARMO adapting) {
        super(adapting);
    }

    @Override
    public Enchantment getEnchantment() {
        FormID enchFormId = getRawObject().getEnchantment();
        return getFinderFactory().createEnchantmentFinder().find(enchFormId);
    }

    @Override
    public void setEnchantment(Enchantment enchantment) {
        FormID id = getIdProducer().produce(enchantment);
        getRawObject().setEnchantment(id);
    }

    @Override
    public Armor getTemplate() {
        FormID templateFormId = getRawObject().getTemplate();
        return getFinderFactory().createArmorFinder().find(templateFormId);
    }

    @Override
    public void setTemplate(Armor template) {
        FormID id = getIdProducer().produce(template);
        getRawObject().setTemplate(id);
    }

    @Override
    public Set<Keyword> getKeywords() {
        Collection<FormID> keyWordFormIds = getRawObject().getKeywordSet().getKeywordRefs();
        Collection<Keyword> keyWords = getFinderFactory().createKeywordFinder().find(keyWordFormIds);

        return Collections.unmodifiableSet(new HashSet<>(keyWords));
    }

    @Override
    public void addKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().addKeywordRef(keyword.getForm());
    }

    @Override
    public void removeKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().removeKeywordRef(keyword.getForm());
    }

    @Override
    public Collection<Armature> getArmatures() {
        Collection<FormID> armatureFormIds = getRawObject().getArmatures();
        Collection<Armature> armatures = getFinderFactory().createArmatureFinder().find(armatureFormIds);
        return Collections.unmodifiableCollection(armatures);
    }

    @Override
    public void addArmature(Armature armature) {
        getRawObject().addArmature(armature.getForm());
    }

    @Override
    public void removeArmature(Armature armature) {
        getRawObject().removeArmature(armature.getForm());
    }

    @Override
    public JSkyModel getModel(Gender gender) {
        return getBridgeFactory().createBridge(this, gender);
    }

    @Override
    public JSkySound getPickupSound() {
        FormID soundId = getRawObject().getPickupSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setPickupSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setPickupSound(id);
    }

    @Override
    public JSkySound getDropSound() {
        FormID soundId = getRawObject().getDropSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setDropSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setDropSound(id);
    }

    @Override
    public EquipSlot getEquipSlot() {
        FormID id = getRawObject().getEquipSet();
        return getFinderFactory().createEquipSlotFinder().find(id);
    }

    @Override
    public void setEquipSlot(EquipSlot slot) {
        FormID id = getIdProducer().produce(slot);
        getRawObject().setEquipSlot(id);
    }

    @Override
    public ImpactSet getBlockImpactSet() {
        FormID id = getRawObject().getBashImpactData();
        return getFinderFactory().createImpactSetFinder().find(id);
    }

    @Override
    public void setBlockImpactSet(ImpactSet bashImpactData) {
        FormID id = getIdProducer().produce(bashImpactData);
        getRawObject().setBashImpactData(id);
    }

    @Override
    public Race getRace() {
        FormID id = getRawObject().getRace();
        return getFinderFactory().createRaceFinder().find(id);
    }

    @Override
    public void setRace(Race race) {
        FormID id = getIdProducer().produce(race);
        getRawObject().setRace(id);
    }

    @Override
    public int getValue() {
        return getRawObject().getValue();
    }

    @Override
    public void setValue(int value) {
        getRawObject().setValue(value);
    }

    @Override
    public float getWeight() {
        return getRawObject().getWeight();
    }

    @Override
    public void setWeight(float weight) {
        getRawObject().setWeight((float) weight);
    }

    @Override
    public float getArmorRating() {
        return getRawObject().getArmorRatingFloat();
    }

    @Override
    public void setArmorRating(float rating) {
        getRawObject().setArmorRatingFloat((float) rating);
    }

    @Override
    public JSkyScriptPackage getScriptPackage() {
        ScriptPackage scriptPackage = getRawObject().getScriptPackage();
        return getBridgeFactory().createBridge(scriptPackage);
    }

    @Override
    public boolean getFlag(BodyTemplate.GeneralFlags flag) {
        return getRawObject().getBodyTemplate().get(flag);
    }

    @Override
    public void setFlag(BodyTemplate.GeneralFlags flag) {
        getRawObject().getBodyTemplate().set(flag, true);
    }

    @Override
    public void unsetFlag(BodyTemplate.GeneralFlags flag) {
        getRawObject().getBodyTemplate().set(flag, false);
    }

    @Override
    public JSkyBodyTemplate getBodyTemplate(BodyTemplate.BodyTemplateType type) {
        BodyTemplate bodyTemplate = getRawObject().getBodyTemplate();
        return getBridgeFactory().createBridge(bodyTemplate);
    }
}
